<html>
<head>
	<meta charset="UTF-8">
	<title>配置</title>
	{load href="__CSS__/bootstrap.min.css"/}

	<script src="__JS__/jquery-1.10.2.min.js"></script>
	<script type="text/javascript" src="__JS__/jquery.form.js"></script>
</head>
<body>

<div class="col-sm-12">
	<form id="myform" action="{if condition="$action_name=='add'"}{:U('Payment/add')}{else /}{:U('Payment/edit')}{/if}" method="post">

		<h3>基本设置</h3>
		<div class="form-group row">
			<label class="form-control-label col-sm-2">支付方式：</label>
			<div class="col-sm-10">
				<p class="form-control-static">{$vo.pay_name}</p>
			</div>
		</div>
		<div class="form-group row">
			<label class="form-control-label col-sm-2">支付名称：</label>
			<div class="col-sm-10">
				<input type="text" name="pay_name" value="{$vo.pay_name}" class="form-control" id="pay_name"/>
			</div>
		</div>
		<div class="form-group row">
			<label class="form-control-label col-sm-2">描述：</label>
			<div class="col-sm-10">
				<textarea name="pay_desc" class="form-control" rows="3">{$vo[pay_desc]}</textarea>
			</div>
		</div>
		<div class="form-group row">
			<label class="form-control-label col-sm-2">在线支付：</label>
			<div class="col-sm-10">
				<p class="form-control-static">{notempty name="vo.is_online"}是{else/}否{/notempty}</p>
			</div>
		</div>
		<div class="form-group row">
			<label class="form-control-label col-sm-2">按比例收费：</label>
			<div class="col-sm-10" id="pay_fee">
				<input name="pay_fee_type" value="0" type="radio" {empty name="vo['pay_fee_type']"}checked{/empty}> {:L(pay_method_rate)}&nbsp;&nbsp;&nbsp;
				<input name="pay_fee_type" value="1" type="radio" {notempty name="vo['pay_fee_type']"}checked{/notempty}> {:L(pay_method_fix)}&nbsp;&nbsp;&nbsp;
			</div>
		</div>
		<div class="form-group row">
			<label class="col-sm-2"></label>
			<div class="col-sm-10">
				<div id="rate" {notempty name="vo['pay_fee_type']"}style="display:none"{/notempty}>
				费率<input type="text" style="width:30px" value="{$vo.pay_fee}" name="pay_rate">说明：顾客将支付订单总金额乘以此费率作为手续费；
			</div>
			<div id="fix" {empty name="vo['pay_fee_type']"}style="display:none"{/empty}>
			金额<input type="text" name="pay_fix" style="width:30px" value="{$vo.pay_fee}">&nbsp;&nbsp;&nbsp;&nbsp; 说明：顾客每笔订单需要支付的手续费；
		</div>
</div>
</div>


	<h3>参数设置</h3>

	{volist name="vo[config]" id="r"}
	{if condition="$r['type']=='text'"}
	<div class="form-group row">
		<label class="col-sm-2 form-control-label">{:L($r[name])}</label>
		<div class="col-sm-10">
			<input type="text"  class="form-control" name="pay_config[{$r.name}]" id="{$r.name}" value="{$r.value}" size="40" />
		</div>
	</div>
	{else/}
	<div class="form-group row">
		<label class="col-sm-2 form-control-label">{:L($r[name])}</label>
		<div class="col-sm-10">
			{:Form::select(array('field'=>'pay_config['.$r[name].']','options'=>$r[option]),$r[value])}
		</div>
	</div>
	{/if}
	{/volist}

<div class="form-group row">
	<div class="col-sm-12">
		<div class="pull-sm-right">
			<input type="hidden" name="id" value="{$vo.id}" />
			<input type="hidden" name="pay_code" value={$vo.pay_code} />
			<input type="hidden" name="is_cod" value={$vo.is_cod} />
			<input type="hidden" name="is_online" value={$vo.is_online} />
			<input class="btn btn-primary" type="submit" value="提交">
		</div>
	</div>
</div>
</form>
</div>

<script>
$(document).ready(function() {
	$("#pay_fee input[type='radio']").click( function () {
		if($(this).val()== 0){
			$("#rate").show();
			$("#fix").hide();
			$("#rate input").val('0');
		} else {
			$("#fix").show();
			$("#rate").hide();
			$("#fix input").val('0');
		}
	});
});

var index = parent.layer.getFrameIndex(window.name); //获取窗口索引

$(document).ready(function() {
	$('#myform').ajaxForm({
		success:  complete,  // post-submit callback
		dataType: 'json'
	});
});

function complete(data){
	if (data.status == 1) {
		parent.layer.msg(data.info, {
			icon: 1,
			time: 5000 //2秒关闭（如果不配置，默认是3秒）
		});
		parent.location.reload();
		parent.layer.close(index);
	} else {
		layer.msg(data.info, {
			icon: 2,
			time: 2000 //2秒关闭（如果不配置，默认是3秒）
		});
	}
}
</script>

</body>
</html>
